package com.wt.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import java.time.Instant;

/**
 * @Auther: wtt
 * @Date: 2022/1/15 15:28
 * @Description:
 */
@Activate(group = {CommonConstants.CONSUMER, CommonConstants.PROVIDER})
public class InvokeFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        long startTime = Instant.now().toEpochMilli();
        try {
            return invoker.invoke(invocation);
        } finally {
            System.out.println("invoke Time:" + (Instant.now().toEpochMilli() - startTime) + "ms");
        }
    }
}
